﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using Repid.Entity;

namespace Repid.Core.Configuration
{
    /// <summary>
    /// 实体配置器
    /// </summary>
    /// <typeparam name="T">类型</typeparam>
    internal abstract class EntityConfigurationBase<T> : EntityTypeConfiguration<T>, IEntityConfiguration where T : EntityBase
    {
        /// <summary>
        /// 实体映射
        /// </summary>
        private void ConfigurationInitialization()
        {
            PrimaryInitialization();
            MapperInitialization();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        internal EntityConfigurationBase()
        {
            ConfigurationInitialization();
        }

        /// <summary>
        /// 设置主键
        /// </summary>
        internal virtual void PrimaryInitialization()
        {
            HasKey(m => m.ID);
        }

        /// <summary>
        /// 设置映射
        /// </summary>
        internal abstract void MapperInitialization();

        /// <summary>
        /// 将实体配置对象注册到实体生成器配置集合
        /// </summary>
        /// <param name="configurations">实体生成器配置集合</param>
        public void AddTo(ConfigurationRegistrar configurations)
        {
            configurations.Add(this);
        }
    }
}